home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
edit
/
jwpsrc.zip
/
MISC.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-03-31
|
43KB
|
1,286 lines
/* Copyright (C) Stephen Chung, 1991-1993. All rights reserved. */
#include "jwp.h"
#include "idm.h"
#include <dir.h>
#include <sys/stat.h>
static long int percent, ohpercent;
static int HeaderNum;
static BOOL LeftRight;
static char *filespec = NULL;
static KANJI far *criteria[NRSUMMARIES] = { NULL, NULL, NULL, NULL, NULL };
static char *FileInfoName;
extern BOOL Dialogs3D;
#define PARENTDIR "<Go Up>"
#define DRIVECHAR '['
#define FILENAMELEN 15
#define NRQUICKFILE 4
#define NRPROGS 4
static char *QuickFiles[NRQUICKFILE];
#define TPLBLOCKSIZE 5
typedef struct {
char far *filename;
KANJI far *desc;
} TPLFILE;
char far *TplChosen = NULL;
static TPLFILE far *Templates = NULL;
static int nr_templates = 0;
BOOL FAR PASCAL StatisticsProc (HWND hwnd, WORD message, WORD wParam, LONG lParam)
{
long int allocated, requests, hits, usage, overhead;
long int len;
int num;
HWND barhwnd;
RECT rect;
HDC hdc;
char buffer[BUFSIZE];
switch (message) {
case WM_INITDIALOG:
FontCacheStatistics (&num, &usage, &requests, &hits);
sprintf(buffer, "%d Font Cache%s:", num, (num > 1) ? "s" : "");
SetDlgItemText(hwnd, 4201, buffer);
if (requests > 0L) {
sprintf(buffer, "%ld / %ld (%d%%) %ld cached",
hits, requests, (int) (100.0 * ((double) hits) / ((double) requests)), usage);
} else {
sprintf(buffer, "%ld cached", usage);
}
SetDlgItemText(hwnd, 4202, buffer);
ConvCacheStatistics (&usage, &requests, &hits);
if (requests > 0L) {
sprintf(buffer, "%ld / %ld (%d%%) %ld cached",
hits, requests, (int) (100.0 * ((double) hits) / ((double) requests)), usage);
} else {
sprintf(buffer, "%ld cached", usage);
}
SetDlgItemText(hwnd, 4212, buffer);
if (global.active != NULL) {
sprintf(buffer, "%ld character%s", global.active->nr_bytes,
(global.active->nr_bytes > 1L) ? "s" : "");
SetDlgItemText(hwnd, 4221, buffer);
if (global.active->undolevels > 0) {
sprintf(buffer, "%d change%s retained", global.active->undolevels,
(global.active->undolevels > 1) ? "s" : "");
} else {
strcpy(buffer, "No changes retained");
}
SetDlgItemText(hwnd, 4222, buffer);
} else {
SetDlgItemText(hwnd, 4221, "No active file");
}
CountMemoryUsage(&allocated, &usage, &overhead);
sprintf(buffer,"Memory Usage Efficiency (%ldK Allocated):", (allocated / 1024L) + 1);
SetDlgItemText(hwnd, 4231, buffer);
percent = (((usage + overhead) * 100L) / allocated) + 1L;
if (percent > 100L) percent = 100L;
ohpercent = ((usage * 100L) / allocated) + 1L;
if (ohpercent > 100L) ohpercent = 100L;
sprintf(buffer,"%ld%%", percent);
SetDlgItemText(hwnd, 4233, buffer);
CenterDialogBox(hwnd);
return (TRUE);
case WM_PAINT:
barhwnd = GetDlgItem(hwnd, 4232);
GetClientRect(barhwnd, &rect);
len = (rect.right - 4) * percent / 100L;
hdc = GetDC(barhwnd);
SelectObject(hdc, GetStockObject(GRAY_BRUSH));
Rectangle(hdc, 2, 2, len + 2, rect.bottom - 2);
len = (rect.right - 4) * ohpercent / 100L;
if (Dialogs3D) {
SelectObject(hdc, GetStockObject(BLACK_BRUSH));
} else {
SelectObject(hdc, GetStockObject(LTGRAY_BRUSH));
}
Rectangle(hdc, 2, 2, len + 2, rect.bottom - 2);
ReleaseDC(barhwnd, hdc);
break;
case WM_KEYDOWN:
switch (wParam) {
case VK_ESCAPE: SendMessage(hwnd, WM_COMMAND, IDOK, 0L);
return (TRUE);
}
break;
case WM_COMMAND:
switch (wParam) {
case IDOK:
case IDCANCEL: EndDialog(hwnd, 0); return (TRUE);
}
break;
}
return (FALSE);
}
BOOL FAR PASCAL SummaryProc (HWND hwnd, WORD message, WORD wParam, LONG lParam)
{
switch (message) {
case WM_INITDIALOG: {
int i, len;
FILEOPTIONS *f, *f1;
KANJI buffer[MAXLINELEN];
/* Set the type and mode-change icon of the Jedit controls */
f1 = global.active;
for (i = 0; i < NRSUMMARIES; i++) {
SendDlgItemMessage(hwnd, 4201 + i, EM_SETRECT, GetDlgItem(hwnd, 4211), 0L);
f = (FILEOPTIONS *) SendDlgItemMessage(hwnd, 4201 + i, EM_GETHANDLE, 0, 0L);
if (f1 != NULL && f1->summary[i] != NULL) {
kanjicpy(buffer, f1->summary[i]);
SendDlgItemMessage(hwnd, 4201 + i, EM_REPLACESEL, 0, (LONG) buffer);
} else {
buffer[0] = 0;
}
if (i == 0) {
len = kanjilen(buffer);
SendDlgItemMessage(hwnd, 4211, EM_SETHANDLE, f->hwnd, 0L); /* icon-change */
}
}
if (len > 0) SendDlgItemMessage(hwnd, 4201, EM_SETSEL, len, MAKELONG(0, len - 1));
SetFocus(GetDlgItem(hwnd, 4201));
CenterDialogBox(hwnd);
return (TRUE);
}
case WM_PAINT: {
int i;
HDC hdc;
PAINTSTRUCT ps;
hdc = BeginPaint(hwnd, &ps);
for (i = 0; i < NRSUMMARIES; i++) DrawBoundingBox(hwnd, hdc, 4201 + i);
EndPaint(hwnd, &ps);
return (TRUE);
}
case WM_COMMAND: {
int i, j, len;
KANJI far *kp;
UNIT far *up;
switch (wParam) {
case IDOK:
if (global.active != NULL) {
for (i = 0; i < NRSUMMARIES; i++) {
up = (UNIT far *) SendDlgItemMessage(hwnd, 4201 + i, EM_GETLINE, 0, 0L);
len = unitlen(up);
if (len <= 0) {
if (global.active->summary[i] != NULL) {
FreeBlock(global.active->summary[i]);
global.active->summary[i] = NULL;
}
} else {
kp = global.active->summary[i];
if (kp == NULL) {
kp = (KANJI far *) BlockAlloc((len + 5) * sizeof(KANJI));
} else if ((SegHeapGetSize(kp) / sizeof(KANJI)) < len + 5) {
FreeBlock(kp);
kp = (KANJI far *) BlockAlloc((len + 5) * sizeof(KANJI));
}
for (j = 0; up[j].kanji; j++) kp[j] = up[j].kanji;
kp[j] = 0;
global.active->summary[i] = kp;
}
}
}
EndDialog(hwnd, TRUE);
return (TRUE);
case IDCANCEL:
EndDialog(hwnd, FALSE);
return (TRUE);
}
break;
}
}
return (FALSE);
}
BOOL FAR PASCAL EditHeaderProc (HWND hwnd, WORD message, WORD wParam, LONG lParam)
{
switch (message) {
case WM_INITDIALOG: {
int i, len;
FILEOPTIONS *f;
KANJI far *kp;
if (LeftRight) {
switch (HeaderNum) {
case 0: SetWindowText(hwnd, "Edit Left Page Header"); break;
case 1: SetWindowText(hwnd, "Edit Right Page Header"); break;
case 2: SetWindowText(hwnd, "Edit Left Page Footer"); break;
case 3: SetWindowText(hwnd, "Edit Right Page Footer"); break;
}
}